package JFrame;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Panel;
import java.awt.Toolkit;
 


import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
 

public class PanelImageTest extends JPanel {
   private Image image;
 
   public PanelImageTest() {
      super();
      setOpaque(true);
 
      image =  new ImageIcon(getClass().getResource("/images/test4.jpg")).getImage();;
   }
 
   public void paintComponent(Graphics g) {
      super.paintComponent(g);
      setBackground(Color.WHITE);
      if (image != null) {
         int height = image.getHeight(this);
         int width = image.getWidth(this);
 
         if (height != -1 && height > getHeight())
            height = getHeight();
 
         if (width != -1 && width > getWidth())
            width = getWidth();
 
         int x = (int) (((double) (getWidth() - width)) / 2.0);
         int y = (int) (((double) (getHeight() - height)) / 2.0);
         g.drawImage(image, x, y, width, height, this);
      }
   }
 
 
}